package com.spartez.farhorizons.client;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.Component;
import com.gwtext.client.widgets.event.ButtonListener;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
import com.gwtext.client.widgets.menu.Menu;

public class NavPanel extends HorizontalPanel {
	private final HTML greeting = new HTML("Hello, stranger!");
	
	public NavPanel() {
    	getElement().getStyle().setProperty("backgroundColor", ":FFFF88");
    	setSpacing(8);
    	
    	add(greeting);
    	greeting.setWordWrap(false);
    	
    	add(new GraviticsPanel());
    	
    	Label spacer = new Label();
    	add(spacer);
    	
    	final Button calcTech = new Button("Research costs");
    	calcTech.addListener(new ButtonListenerAdapter() {

			public void onClick(Button button, EventObject e) {
				new TechCalculator().show();
			}

    	});
    	add(calcTech);
    	final UploadRoster uploadRoster = new UploadRoster();
    	add(uploadRoster);
    	setCellWidth(spacer, "100%");
    	
		FarHorizons.greetingService.getUserName(new AsyncCallback<String>() {

			public void onFailure(Throwable caught) {
				greeting.setHTML("<font color=\"red\">Error: " + caught.getMessage() + "</font>");
			}

			public void onSuccess(String result) {
		    	greeting.setHTML("Hello, " + result + "! (<a href=\"/?logout=1\">logout</a>)");
			}
    	});
    }
}
